package com.example.demo.common;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Aspect
@Component
public class UserAOP {
    @Pointcut("execution(* com.example.demo.controller.UserController.*(..))")
    public void pointcut(){

    }
    //前置通知
    @Before("pointcut()")
    public void doBefore(){
        System.out.println("执行了前置通知："+ LocalDateTime.now());
    }


    @After("pointcut()")
    public void doAfter(){
        System.out.println("执行了后置通知："+ LocalDateTime.now());
    }

    @Around("pointcut()")
    public Object doAround(ProceedingJoinPoint joinPoint){
        System.out.println("开始执行环绕通知");
        Object object = null;
        try {
            object = joinPoint.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
        System.out.println("环绕通知执行结束");
        return object;
    }
}
